/*    */ package com.zimbra.cs.stats;
/*    */ 
/*    */ import com.zimbra.common.stats.Counter;
/*    */ import com.zimbra.common.stats.StatsDumperDataSource;
/*    */ import java.util.ArrayList;
/*    */ import java.util.Collection;
/*    */ import java.util.List;
/*    */ import java.util.concurrent.ConcurrentHashMap;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class ActivityTracker
/*    */   implements StatsDumperDataSource
/*    */ {
/*    */   private String mFilename;
/* 36 */   private ConcurrentHashMap<String, Counter> mCounterMap = new ConcurrentHashMap();
/*    */   
/*    */   public ActivityTracker(String filename)
/*    */   {
/* 40 */     this.mFilename = filename;
/*    */   }
/*    */   
/*    */   public void addStat(String commandName, long startTime) {
/* 44 */     Counter counter = getCounter(commandName);
/* 45 */     counter.increment(System.currentTimeMillis() - startTime);
/*    */   }
/*    */   
/*    */   private Counter getCounter(String commandName) {
/* 49 */     Counter counter = (Counter)this.mCounterMap.get(commandName);
/* 50 */     if (counter == null) {
/* 51 */       counter = new Counter();
/*    */       
/* 53 */       Counter previousCounter = (Counter)this.mCounterMap.putIfAbsent(commandName, counter);
/* 54 */       if (previousCounter != null)
/*    */       {
/*    */ 
/* 57 */         counter = previousCounter;
/*    */       }
/*    */     }
/* 60 */     return counter;
/*    */   }
/*    */   
/*    */ 
/*    */   public Collection<String> getDataLines()
/*    */   {
/* 66 */     if ((this.mCounterMap == null) || (this.mCounterMap.size() == 0)) {
/* 67 */       return null;
/*    */     }
/* 69 */     List<String> dataLines = new ArrayList(this.mCounterMap.size());
/* 70 */     for (String command : this.mCounterMap.keySet()) {
/* 71 */       Counter counter = (Counter)this.mCounterMap.get(command);
/* 72 */       if (counter.getCount() > 0L)
/*    */       {
/*    */ 
/*    */ 
/* 76 */         long count = counter.getCount();
/* 77 */         long avg = counter.getAverage();
/* 78 */         counter.reset();
/* 79 */         dataLines.add(String.format("%s,%d,%d", new Object[] { command, Long.valueOf(count), Long.valueOf(avg) }));
/*    */       }
/*    */     }
/* 82 */     return dataLines;
/*    */   }
/*    */   
/*    */   public String getFilename() {
/* 86 */     return this.mFilename;
/*    */   }
/*    */   
/*    */   public String getHeader() {
/* 90 */     return "command,exec_count,exec_ms_avg";
/*    */   }
/*    */   
/*    */   public boolean hasTimestampColumn() {
/* 94 */     return true;
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/stats/ActivityTracker.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */